//
//  AyStatus.m
//  xWeibo
//
//  Created by alvis mac on 8/7/15.
//  Copyright (c) 2015 alvis. All rights reserved.
//

#import "AyStatus.h"
#import "NSDateExtend.h"
#import "MJExtension.h"
#import "AyPhoto.h"
#import "AyDefine.h"
#import "MJExtension.h"

@implementation AyStatus

- (NSDictionary *)objectClassInArray
{
    return @{@"pic_urls" : [AyPhoto class]};
}


- (NSString *)createdTime{

    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
    fmt.locale=[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    NSDate *createdDate = [fmt dateFromString:_created_at];
    
    if (createdDate.isToday) { // 今天
        if (createdDate.deltaWithNow.hour >= 1) {
            return [NSString stringWithFormat:@"%ld小时前", (long)createdDate.deltaWithNow.hour];
        } else if (createdDate.deltaWithNow.minute >= 1) {
            return [NSString stringWithFormat:@"%ld分钟前", (long)createdDate.deltaWithNow.minute];
        } else {
            return @"刚刚";
        }
    } else if (createdDate.isYesterday) { // 昨天
        fmt.dateFormat = @"昨天 HH:mm";
        return [fmt stringFromDate:createdDate];
    } else if (createdDate.isThisYear) { // 今年(至少是前天)
        fmt.dateFormat = @"MM-dd HH:mm";
        return [fmt stringFromDate:createdDate];
    } else { // 非今年
        fmt.dateFormat = @"yyyy-MM-dd HH:mm";
        return [fmt stringFromDate:createdDate];
    }
}


- (void)setSource:(NSString *)source
{
    int jianLoc = [source rangeOfString:@">"].location;
    if (jianLoc == -1) {
        _source = [source copy];
    } else {
        int loc = jianLoc + 1;
        int length = [source rangeOfString:@"</"].location - loc;
        source = [source substringWithRange:NSMakeRange(loc, length)];
        
        _source = [NSString stringWithFormat:@"来自%@", source];
    }
}

MJCodingImplementation

@end
